package cn.getech.data.metadata.mapper;

import cn.getech.data.development.entity.TableRelationshipEntity;
import cn.getech.data.metadata.controller.blood.BloodUnion;
import cn.getech.data.metadata.entity.meta.CollectionTableInfo;
import cn.getech.data.metadata.model.res.CollectionTableFieldRes;
import cn.getech.data.metadata.model.res.CollectionTableInfoListRes;
import cn.getech.data.metadata.model.res.CollectionTableInfoRes;
import cn.getech.data.metadata.model.res.collectiontablestatistics.RelationTable;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.MapKey;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
public interface CollectionTableMapper extends BaseMapper<CollectionTableInfo> {
    int updateViewCount(Integer id);

    int updateHotCount(Integer id);
    CollectionTableInfoRes info(Integer id);

    List<CollectionTableInfo> listAllPage(Map<String, Object> params);

    IPage<CollectionTableInfo> listPageByRole(Page<CollectionTableInfo> page, @Param("params")  Map<String, Object> params);
    IPage<CollectionTableInfoListRes> listPage(Page<CollectionTableInfoListRes> collectionTableInfoListResPage,
                                               @Param("params") Map<String, Object> params);

    CollectionTableInfo selectHiveTableById(Integer id);

    String selectPrimarykey();

    Integer selectBdpTableId(@Param("dbName") String dbName, @Param("tableName") String tableName);

    List<Integer> selectTableIds(@Param("id") Integer id);

    @MapKey("db_name")
    Map<String, Object> selectBdpTable(Integer resultTableId);

    boolean deleteRelationship(@Param("param") TableRelationshipEntity tableRelationshipEntity );


   List<TableRelationshipEntity> selectRelationship(@Param("param") TableRelationshipEntity tableRelationshipEntity );

   // 根据source_id 还有数据库 名获取 表
   @MapKey("id")
    List<Map<String, Object>>   selectTableBysourceAndDb(@Param("params") Map<String,Object> params);

    // 获取表字段
    List<CollectionTableFieldRes> selectTableFieldByTableId( @Param("id") Integer id);

    @MapKey("id")
    List<Map<String, Object>> selectTableBySourceAndDbByConfig(@Param("sourceConf") String sourceConf, @Param("params")Map<String, Object> params);

    int batchInsertTableDbUsers(@Param("tableIds") Set<Integer> tableIds, @Param("dbUserName") String dbUserName);

    int deleteTableDbUsers(@Param("tableDeletes") List<CollectionTableInfo> tableDeletes,@Param("dbUserName") String dbUserName);



    String selectTableOwner(@Param("id") Integer id);

    List<RelationTable> selectRelationTable(@Param("ids")  Set<Integer> ids);

    List<RelationTable> selectMetaTable(@Param("ids")  List<Integer> ids);

    BloodUnion selectException(BloodUnion bloodUnion);

    CollectionTableInfo selectMetaTableInfo(@Param("id")  Integer id);

    @MapKey("id")
    List<Map<Integer,String>> listUserList(@Param("tenantId") Integer tenantId);

    List<Integer> selectCollectionTableIds(@Param("list") List<Integer> list);

    List<Integer> selectCategoryIds(@Param("id")  Integer id);

    List<String> selectCategoryNames(@Param("list") List<Integer> list);

    String searchTablecategoryNames(@Param("tableId")  Integer tableId);

    int saveCollectionTableCategory(@Param("tableId") Integer tableId,@Param("taskId") Long taskId,
                                    @Param("tenantId") Integer tenantId,@Param("userId") Integer userId);

}